package com.ruoyi.web.controller.community.electronicCommerce;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.community.domain.EcActivity;
import com.ruoyi.community.service.ec.IEcActivityService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 社区电商Controller
 * 
 * @author ruoyi
 * @date 2021-08-15
 */
@RestController
@RequestMapping("/e-commerce/activity")
public class EcActivityController extends BaseController
{
    @Autowired
    private IEcActivityService ecActivityService;

    /**
     * 查询社区电商列表
     */
    @PreAuthorize("@ss.hasPermi('e-commerce:activity:list')")
    @GetMapping("/list")
    public TableDataInfo list(EcActivity ecActivity)
    {
        startPage();
        List<EcActivity> list = ecActivityService.selectEcActivityList(ecActivity);
        return getDataTable(list);
    }

    /**
     * 导出社区电商列表
     */
    @PreAuthorize("@ss.hasPermi('e-commerce:activity:export')")
    @Log(title = "社区电商", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(EcActivity ecActivity)
    {
        List<EcActivity> list = ecActivityService.selectEcActivityList(ecActivity);
        ExcelUtil<EcActivity> util = new ExcelUtil<EcActivity>(EcActivity.class);
        return util.exportExcel(list, "社区电商数据");
    }

    /**
     * 获取社区电商详细信息
     */
    @PreAuthorize("@ss.hasPermi('e-commerce:activity:query')")
    @GetMapping(value = "/{activityId}")
    public AjaxResult getInfo(@PathVariable("activityId") Integer activityId)
    {
        return AjaxResult.success(ecActivityService.selectEcActivityById(activityId));
    }

    /**
     * 新增社区电商
     */
    @PreAuthorize("@ss.hasPermi('e-commerce:activity:add')")
    @Log(title = "社区电商", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody EcActivity ecActivity)
    {
        return toAjax(ecActivityService.insertEcActivity(ecActivity));
    }

    /**
     * 修改社区电商
     */
    @PreAuthorize("@ss.hasPermi('e-commerce:activity:edit')")
    @Log(title = "社区电商", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody EcActivity ecActivity)
    {
        return toAjax(ecActivityService.updateEcActivity(ecActivity));
    }

    /**
     * 删除社区电商
     */
    @PreAuthorize("@ss.hasPermi('e-commerce:activity:remove')")
    @Log(title = "社区电商", businessType = BusinessType.DELETE)
	@DeleteMapping("/{activityIds}")
    public AjaxResult remove(@PathVariable Integer[] activityIds)
    {
        return toAjax(ecActivityService.deleteEcActivityByIds(activityIds));
    }
}
